﻿using CoreCms.Net.Utility.Helper;
using Microsoft.AspNetCore.Mvc;
using System.Collections;

namespace CoreCms.Net.Web.Html.Controllers
{
    public class QrcodeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }
        //http://fruits.zzcloud6.com/qrcode/content/durian.html
        #region 动态二维码页面

        public async Task<IActionResult> Content()
        {
            string id = "" + Request.RouteValues["id"];
            id = id.Replace(".html", "");
            if (string.IsNullOrEmpty(id)) { id = "durian"; }
            string url = "http://k8zapi.zzcloud6.com/api/article/getarticledetail2";
            Dictionary<string, string> @params = new Dictionary<string, string>();
            @params.Add("id", id);
            string result = await HttpHelper.HttpPostAsync(url, @params);
            Hashtable dyRes = Newtonsoft.Json.JsonConvert.DeserializeObject<Hashtable>(result);
            if (!Convert.ToBoolean(dyRes["status"]))
                return Content("" + dyRes["msg"]);
            dynamic entity = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>("" + dyRes["data"]);

            ViewData["id"] = entity.contentBody;

            return View();
        }


        #endregion
    }
}
